// Copyright (c) 2014 Jonathan Magnan (http://jonathanmagnan.com).
// All rights reserved (http://jonathanmagnan.com/extension-methods-library).
// Licensed under MIT License (MIT) (http://zextensionmethods.codeplex.com/license).

using System.Collections.Generic;
using System.IO;
using System.Linq;

#if EXTENSIONMETHODS_WITHNAMESPACE
namespace JHSoft.Extension.ExtensionMethods
{
#endif
#if EXTENSIONMETHODS_INTERNAL
    internal static partial class DirectoryInfoExtensions
#else
    public static partial class DirectoryInfoExtensions
#endif
    {
        /// <summary>
        ///     Combines multiples string into a path.
        /// </summary>
        /// <param name="this">The @this to act on.</param>
        /// <param name="paths">A variable-length parameters list containing paths.</param>
        /// <returns>
        ///     The combined paths as a FileInfo. If one of the specified paths is a zero-length string, this method returns
        ///     the other path.
        /// </returns>
        /// <example>
        ///     <code>
        ///           using System;
        ///           using System.IO;
        ///           using Microsoft.VisualStudio.TestTools.UnitTesting;
        ///           using JHSoft.Extension.ExtensionMethods;
        ///           
        ///           namespace ExtensionMethods.Examples
        ///           {
        ///               [TestClass]
        ///               public class System_IO_DirectoryInfo_PathCombineFile
        ///               {
        ///                   [TestMethod]
        ///                   public void PathCombine()
        ///                   {
        ///                       // Type
        ///                       var @this = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
        ///           
        ///                       string path1 = &quot;Fizz&quot;;
        ///                       string path2 = &quot;Buzz&quot;;
        ///           
        ///                       // Exemples
        ///                       FileInfo result = @this.PathCombineFile(path1, path2); // Combine path1 and path2 with the DirectoryInfo
        ///           
        ///                       // Unit Test
        ///                       var expected = new FileInfo(Path.Combine(@this.FullName, path1, path2));
        ///                       Assert.AreEqual(expected.FullName, result.FullName);
        ///                   }
        ///               }
        ///           }
        ///     </code>
        /// </example>
        public static FileInfo PathCombineFile(this DirectoryInfo @this, params string[] paths)
        {
            List<string> list = paths.ToList();
            list.Insert(0, @this.FullName);
            return new FileInfo(Path.Combine(list.ToArray()));
        }
    }
#if EXTENSIONMETHODS_WITHNAMESPACE
}
#endif